#---------------------------------------------------------
# iomux
#---------------------------------------------------------

namespace eval iomux {
    variable fp_list [list ]
    variable services {}
    namespace eval service {}

    proc init {service {prefix ""}} {
        namespace eval service::$service {
	    variable fp_list [list ]
            variable prefix ""

	    proc mk_pipe {fp} {
		variable fp_list
		lappend fp_list $fp
	    }

	    proc rm_pipe {fp} {
		variable fp_list
		set i [lsearch $fp_list $fp]
		if {$i < 0} {
		    return
		}
		set fp_list [lreplace $fp_list $i $i]
	    }

	    proc puts {line} {
		variable fp_list
                variable prefix
		foreach fp $fp_list {
		    ::puts $fp "$prefix$line"
		    ::flush $fp
		}
	    }

        } ;# end namespace service::${service}

        set service::${service}::prefix $prefix
        return iomux::service::${service}
    }

}


